<!--suppress ALL -->
<template>
	<view class="global__theme0 index-page">
		111111111112222
	</view>
</template>

<script>
	const db = wx.cloud.database()
	const _ = db.command
	import {dateFormat} from '../../utils/index'

	let startIndex, endIndex, touchIndex;
	export default {
		components: {
		},
		data() {
			return {
				uid: '',
				opacity: 0,
				modalName:null,
				curIndex: 0,
				article: [],
				list: [],
				page: 1,
				start: 0,
				end: 0,
				loadProgress: 0,
				statusBar: this.StatusBar,
				customBar: this.CustomBar,
				picList: ['http://img18.fn-mart.com/pic/981c13455ad9275d2234/hT82227nvnClKMZlCT/sioGoG_GBGWYSG/CsmRsF8Wo3KALAQsAAiVPpSmCiA822.jpg', 'http://img18.fn-mart.com/pic/981c13455ad9275d2234/hT82227nvnClKMZlCT/sioGoG_GBGWYSG/CsmRsF8Wo3KALAQsAAiVPpSmCiA822.jpg']
			};
		},
		computed: {
			isLogin() {
				return this.uid !== ''
			},
			style() {
				var StatusBar= this.StatusBar;
				var CustomBar= this.CustomBar;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar + StatusBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				} else {
					style = `${style}background-image: linear-gradient(to right, rgba(55,84,80, ${this.opacity}), rgba(81,99,112, ${this.opacity}))`
				}
				return style
			}
		},
		methods: {
			handleClick(e) {
				const { type } = e.currentTarget.dataset
				if(type === 'hot') {
					uni.navigateTo({
						url: '/pages/hot/index'
					})
				} else {
					uni.showToast({
						title: '该功能尚未开通', icon: 'none'
					})
				}
			},
			showModal(e) {
				this.modalName = e.currentTarget.dataset.target
			},
			hideModal(e) {
				this.modalName = null
			},
			scrollBody(e) {
				const {scrollTop} = e.detail
				const temp = scrollTop/50
				this.opacity = temp > 1 ? 1 : temp
			},
			reachBottom() {
				this.page++;
				this.getList()
			},
			// 模拟加载数据
			async getList() {
				this.LoadProgress()
				const data = await db.collection('articles').where({
					public: _.eq('发布')
				}).get()
				this.list = [...this.list, ...data.data.map(item => {
					item.createTime = dateFormat(item.createTime, 'yyyy.MM.dd')
					item.updateTime =  dateFormat(item.updateTime,'yyyy.MM.dd')
					return item
				})];
			},
			swiperChange(e) {
				let current = e.detail.current;
				this.curIndex = current;
			},
			handleLink(item) {
				uni.navigateTo({
					url: '/pages/detail/index?id=' + item._id
				})
			},
			handleTouchMove(e) {
				e.preventDefault();
				touchIndex = e.changedTouches[0].pageX; //获取到移动时不断改变的X轴上的值
				let tranBack = touchIndex - startIndex;
				if(tranBack > 100) {
					this.modalName = 'viewModal'
				}
			},
			handleTouchStart(e) {
				let touch = e.changedTouches[0];
				startIndex = touch.pageX;//获取到刚开始的X轴上的值
			},
			async logout() {
				await this.$api.logout()
			},
			LoadProgress(e) {
				this.loadProgress = this.loadProgress + 3;
				if (this.loadProgress < 100) {
					setTimeout(() => {
						this.LoadProgress();
					}, 50)
				} else {
					this.loadProgress = 0;
				}
			},
			getWeixinCode() {
				return new Promise((resolve, reject) => {
					// #ifdef MP-WEIXIN
					uni.login({
						provider: 'weixin',
						success(res) {
							resolve(res.code)
						},
						fail(err) {
							reject(new Error('微信登录失败'))
						}
					})
					// #endif
				})
			},
			loginByWeixin() {
				this.getWeixinCode().then((code) => {
					return uniCloud.callFunction({
						name: 'user-center',
						data: {
							action: 'loginByWeixin',
							params: {
								code,
							}
						}
					})
				}).then((res) => {
					uni.showModal({
						showCancel: false,
						content: '登录成功'
					})
					if (res.result.code === 0) {
						this.uid = res.result.uid
						uni.setStorageSync('uniIdToken', res.result.token)
						uni.setStorageSync('uni_id_token_expired', res.result.tokenExpired)
					}
				}).catch((e) => {
					console.error(e)
					uni.showModal({
						showCancel: false,
						content: '微信登录失败，请稍后再试'
					})
				})
			},
			logout() {
				uniCloud.callFunction({
					name: 'user-center',
					data: {
						action: 'logout'
					},
					success(e) {
						uni.showModal({
							showCancel: false,
							content: '您已退出'
						})
						uni.removeStorageSync('uniIdToken')
						uni.removeStorageSync('uni_id_token_expired')
					},
					fail(e) {
						console.error(e)
						uni.showModal({
							showCancel: false,
							content: '登出失败，请稍后再试'
						})
					}
				})
			},
		},
		async onLoad(query) {
			this.getList()
		},
		async onShow() {
			const {result} = await this.$api.checkToken()
			if(result.code === 0) {
				this.uid = result.uid
				uni.setStorageSync('uniIdToken', result.token)
				uni.setStorageSync('uni_id_token_expired', result.tokenExpired)
			}
		},
	}
</script>

<style lang="scss" scoped>

	.index-page {
		height: 100vh;
		background: url("#{$http}/VKCEYUGU-unidf07c07/05192530-d070-11ea-b244-a9f5e5565f30.png") repeat;
		&__con {
			position: relative;
			height: 100%;
			width: 100%
		}
	}

	.index-header {
		position: fixed;
		top: 0;
		left:0;
		z-index: 92;
		width: 100%;
	}
	/*https://image.weilanwl.com/color2.0/plugin/wdh2236.jpg*/
/*/VKCEYUGU-unidf07c07/f6e052a0-dc67-11ea-8ff1-d5dcf8779628.gif*/

	.index-avatar {
		display: flex;
		flex-direction: column;
		justify-content: center;
		margin: 0 60rpx 60rpx;
		border-radius: 20rpx;
		background-color: var(--box-back-color);

		.avatar-con {
			width: 200upx;
			height: 200upx;
			border-radius: 50%;
			overflow: hidden;
			margin: 20rpx auto;
		}

		.user-name {
			font-size: 28rpx;
			font-weight: bold;
			text-align: center;
			color: #fff;
			margin-bottom: 20rpx;
		}
	}

	.custom-bar {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		font-weight: bold;
		color: #fff;
		text-shadow:0 0 1px #452d2d,0 0 1px #FFFFFB,0 0 2px #FFFFFB;
	}

	.cu-list.card-menu {
		margin: 60rpx;
		background-color: var(--box-back-color);
	}

	.gif-black{
		mix-blend-mode: screen;
	}
	.gif-white{
		mix-blend-mode: multiply;
	}



	.index-nav {
		position: relative;
		width: 100%;
		background: url("https://vkceyugu.cdn.bspapp.com/VKCEYUGU-unidf07c07/df0f4b50-dd38-11ea-8a36-ebb87efcf8c0.png") no-repeat;
		background-size: 100% 100%;
		color: #fff;
		.title {
			padding-left: 56rpx;
			font-size: 36rpx;
			font-weight: bold;
			line-height: 1.8;
		}
		.sub-title {
			padding-left: 56rpx;
			font-size: 24rpx;
		}
		.waves {
			position: absolute;
			bottom: 0;
			width: 100%;
			image {
				border-radius: 0;
			}
		}
	}

	.nav-bar {
		position: relative;
		width: 100%;
		height: 100%;
	}

	.my {
		&-order {
			position: relative;
			z-index: 1000;
			border-radius: 18rpx;
			margin: 50rpx 24rpx 0;
			padding: 10rpx 24rpx 20rpx;
		}
	}

	.info {
		&__content {
			@include flex(center,flex-start);
			margin-left: 24rpx;
		}
		&__wrap {
			padding-top: 50rpx;
			padding-bottom: 110rpx;
			@include flex(center,space-between);
		}
		&__pic {
			width: 100rpx;
			height: 100rpx;
			margin-right: 30rpx;
			border-radius: 50%;
			background-color: #4cd964;
			overflow:hidden;
			image {
				width: 100%;
				height: 100%;
				border-radius: 50%;
			}
		}
		&__name {
			font-size: 28rpx;
			font-weight: bold;
		}
	}

	.order {
		&__title {
			font-size: 32rpx;
			color: #333;
			font-weight: bold;
		}
		&__tips {
			color: #999;
			font-size: 24rpx;
		}
		&__arrow {
			font-size: 28rpx;
			color: #bbb;
		}
		&__wrap {
			@include flex(center, space-around)
		}
		&__item {
			@include flex(center,center);
			flex-direction: column;
		}
		&__icon {
			font-size: 50rpx;
			margin-bottom: 10rpx;
		}
		&__name {
			color: #fff;
			font-size: 26rpx;
			font-weight: bold;
		}
	}

	.flex {
		&-start {
			@include flex(center,start);
			text {
				transform: rotate(-90deg);
			}
		}
		&-between {
			@include flex(center,space-between);
		}
	}

	.meta-footer {
		position: absolute;
		bottom: 0;
		width: 100%;
		padding: 1rem;
		text-align: center;
		line-height: 1.4em;
		background-color: var(--box-back-color);
		&__info {
			display: flex;
			align-items: center;
			justify-content: center;
			margin: .25rem 0;
			font-size: 26rpx;
			word-wrap: break-word;
			line-height: 1.8;
			.iconfont {
				font-size: 26rpx;
				font-weight: normal;
				margin-right: 4rpx;
			}
			text:last-child {
				margin-right: 2px;
				vertical-align: -1px;
				font-size: 26rpx;
			}
		}
		&__word {
			font-size: 24rpx;
			text {
				margin-left: 10rpx;
				border-bottom: 1px dotted #85889b;
				&:first-child, &:last-child {
					border-bottom: none;
				}
			}
		}
	}


</style>
